/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.altius.web.controller;

import cc.altius.model.Category;
import cc.altius.model.Designation;
import cc.altius.model.HealthSpringCenter;
import cc.altius.model.HealthSpringContact;
import cc.altius.service.CenterService;
import cc.altius.service.DesignationService;
import cc.altius.service.HealthSpringContactService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 *
 * @author yogesh
 */
@Controller
@RequestMapping("/admin/")
public class HealthSpringContactController {

    @Autowired
    private HealthSpringContactService healthSpringContactService;
    @Autowired
    private DesignationService designationService;
    @Autowired
    private CenterService centerService;

    @RequestMapping(value = "addHealthSpringContact", method = RequestMethod.GET)
    public String addHealthSpringContact(ModelMap modelMap) {
        HealthSpringContact healthSpringContact = new HealthSpringContact();
        modelMap.addAttribute("healthSpringContact", healthSpringContact);
        List<Category> CategoryList = this.healthSpringContactService.getCategoryList();
        modelMap.addAttribute("CategoryList", CategoryList);
        List<Designation> designationList = this.designationService.getDesignationList();
        modelMap.addAttribute("designationList", designationList);
        List<HealthSpringCenter> healthSpringCenterList = this.centerService.getCenterList();
        modelMap.addAttribute("healthSpringCenterList", healthSpringCenterList);
        return "/admin/addHealthSpringContact";
    }

    @RequestMapping(value = "addHealthSpringContact", method = RequestMethod.POST)
    public String addHealthSpringContact(@ModelAttribute("healthSpringContact") HealthSpringContact healthSpringContact) {
        this.healthSpringContactService.addHealthSpringContact(healthSpringContact);
        return "redirect:/admin/listHealthSpringContact.htm?msg=Conatct added successfully";
    }

    @RequestMapping(value = "listHealthSpringContact", method = RequestMethod.GET)
    public String listHealthSpringContact(ModelMap modelMap) {
        modelMap.addAttribute("healthSpringContactList", this.healthSpringContactService.getHealthSpringContactList());
        return "/admin/listHealthSpringContact";
    }

    @RequestMapping(value = "healthSpringContactEdit", method = RequestMethod.GET)
    public String editHealthSpringContact(@RequestParam("healthSpringContactId") int healthSpringContactId, ModelMap modelMap) {
        HealthSpringContact healthSpringContact = this.healthSpringContactService.getHealthSpringContactById(healthSpringContactId);
        modelMap.addAttribute("healthSpringContact", healthSpringContact);
        List<Category> CategoryList = this.healthSpringContactService.getCategoryList();
        modelMap.addAttribute("CategoryList", CategoryList);
        List<Designation> designationList = this.designationService.getDesignationList();
        modelMap.addAttribute("designationList", designationList);
        List<HealthSpringCenter> healthSpringCenterList = this.centerService.getCenterList();
        modelMap.addAttribute("healthSpringCenterList", healthSpringCenterList);
        return "/admin/healthSpringContactEdit";
    }

    @RequestMapping(value = "healthSpringContactEdit", method = RequestMethod.POST)
    public String editHealthSpringContact(@ModelAttribute("healthSpringContact") HealthSpringContact healthSpringContact) {
        this.healthSpringContactService.updateHealthSpringContact(healthSpringContact);
        return "redirect:/admin/listHealthSpringContact.htm?msg=Conatct updated successfully";
    }
}
